import React from "react";
import { inject, observer } from "mobx-react";
import { message } from "antd";

const HOCStoreInter = (WrapComponent) => {
  @inject("setStoreInfo")
  @observer
  class ElementComponent extends React.Component {
    componentDidMount() {
      let { getStoreInter } = this.props.setStoreInfo;
      //查询接口设置
      getStoreInter().then((data) => {
        if (data.data.code === 200) {
          let allData = data.data.data[0];
          this.setForm(allData);
        } else {
          message.error("查询数据失败");
        }
      });
    }
    setForm = (obj) => {
      let { formOne } = this.refs.form.refs;
      formOne.setFieldsValue(obj);
    };
    submit = () => {
      let { formOne } = this.refs.form.refs;
      let {updateStoreInter} = this.props.setStoreInfo
      let key = [
        "sisEikey",
        "sisSmsikey",
        "sisSmstcod",
        "sisSmss",
        "sisAppid",
        "sisAppsecret",
      ];
      let form = formOne.getFieldsValue(key);
      form.sisId = 1
      updateStoreInter(form).then(data=>{
          if (data.data.code === 200) {
              message.success('更新数据成功')
          }else{
              message.error('更新数据失败')
          }
      })
    };
    render() {
      let methods = {
        submit: this.submit,
      };
      return (
        <div>
          <WrapComponent ref="form" {...methods}></WrapComponent>
        </div>
      );
    }
  }
  return ElementComponent;
};

export default HOCStoreInter;
